<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :rules="rules" label-width="90px">
      <el-form-item label="开户名" prop="bankAccName">
        <el-input v-model="form.bankAccName"  placeholder="请输入开户名" maxlength="50"/>
      </el-form-item>
      <el-form-item label="开户行" prop="cardBank">
        <el-input v-model="form.cardBank"  placeholder="请输入开户行" maxlength="100"/>
      </el-form-item>
      <el-form-item label="支行" prop="cardBranch">
        <el-input v-model="form.cardBranch"  placeholder="请输入支行" maxlength="100"/>
      </el-form-item>
      <el-form-item label="开户地" prop="cardLocation">
        <el-input v-model="form.cardLocation"  placeholder="请输入开户地" maxlength="100"/>
      </el-form-item>
      <el-form-item label="联行号" prop="cardDeposit">
        <el-input v-model="form.cardDeposit"  placeholder="请输入联行号" maxlength="100"/>
      </el-form-item>
      <el-form-item label="卡号" prop="cardNo">
        <el-input v-model="form.cardNo"  placeholder="请输入卡号" maxlength="100"/>
      </el-form-item>
    </el-form>
    <div class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
</template>
<script>
import {
  addTransferAccount,
  updateTransferAccount,
  getTransferAccount
} from '@/api/transfer/transferAccount'

export default {
  name: 'transferAccountOperate',
  props:{
    transferAccountId:{
      type:String,
    },
    productId:{
      type:String,
    }
  },
  data(){
    return{
      form: {
        transferAccountId:null,
        status:2,
        tslId:null,
        cardNo: null,
        cardBank:null,
        bookStatus:1,
        isSubscribe:1,
        productId:null,
        cardBranch:null,
        cardDeposit:null,
        bankAccName:null,
        cardLocation:null,
        type:this.$route.query.type,
      },
      rules: {
        bankAccName: [
          { required: true, message: "请输入开户名", trigger: "blur" }
        ],
        cardNo: [
          { required: true, message: "请输入卡号", trigger: "blur" }
        ],
        cardBank: [
          // { required: true, message: "请输入开户行", trigger: "blur" }
        ],
        cardBranch: [
          { required: true, message: "请输入支行", trigger: "blur" }
        ],
      }
    }
  },
  created() {

  },
  methods:{
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.transferAccountId != null) {
            updateTransferAccount(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.cancel();
            });
          } else {
            addTransferAccount(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.cancel();
            });
          }
        }
      });
    },
    cancel(){
      this.$emit('close');
    },
  },
  watch:{
    productId:{
      handler(val){
        if(val){
          this.form.productId = val
        }
      },immediate:true
    },
    transferAccountId:{
      handler(val){
        if(val){
          getTransferAccount(val).then(res=>{
            this.form = res.data
          })
        }else {
          this.form.transferAccountId = null;
        }
      },immediate:true
    }
  }
}
</script>
<style scoped lang="scss">
.el-form{
  margin-bottom: 55px;
}
.dialog-footer{
  left: 0;
  bottom: 0;
  width: 100%;
  display: flex;
  height: 55px;
  padding: 10px 20px;
  position: absolute;
  justify-content: flex-end;
  background-color: #ffffff;
  //box-shadow: 0 0 4px rgba(0, 21, 41, 0.35);
}
</style>
